package com.dayu.gulimall.order.controller;

import com.dayu.gulimall.order.entity.OrderEntity;
import com.dayu.gulimall.order.entity.OrderReturnReasonEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

/**
 * @author dayu
 * @email dayu@foxmail.com
 * @date 2021/4/15:15:32
 * @Description TODO
 */
@RestController
@Slf4j
public class RabbitController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/send")
    public String sendMsg(){

        for (int i = 0; i <10; i++) {
            if (i%2==0){
                OrderReturnReasonEntity entity = new OrderReturnReasonEntity();
                entity.setId(Long.valueOf(i));
                entity.setCreateTime(new Date());
                entity.setName("content --" + i);
                entity.setStatus(i);
                entity.setSort(i);
                rabbitTemplate.convertAndSend("hello-java-exchange", "hello.java",entity,new CorrelationData(UUID.randomUUID().toString()));
            }else {
                OrderEntity orderEntity = new OrderEntity();
                orderEntity.setBillContent(UUID.randomUUID().toString());
                /*
                 *
                 */
                rabbitTemplate.convertAndSend("hello-java-exchange", "hello2.java",orderEntity,new CorrelationData(UUID.randomUUID().toString()));
            }
            log.info("消息发送完成 =="+i);
        }
        return "ok";
    }
}
